package com.zhang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.entity.ShoppingSysMember;
import com.zhang.mapper.ShoppingSysAdminMapper;
import com.zhang.mapper.ShoppingSysMemberMapper;
import com.zhang.service.ShoppingSysMemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.vo.MemberVo;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhangD
 * @since 2021-07-13
 */
@Service
public class ShoppingSysMemberServiceImpl extends ServiceImpl<ShoppingSysMemberMapper, ShoppingSysMember> implements ShoppingSysMemberService {

    @Autowired
    private ShoppingSysMemberMapper shoppingSysMemberMapper;
    @Override
    public String addMember(MemberVo memberVo) {
        ShoppingSysMember member = new ShoppingSysMember();
        member.setLoginName(memberVo.getLoginName());
        member.setMemberName(memberVo.getMemberName());
        member.setPassword(memberVo.getPassword());
        member.setSex(memberVo.getSex());
        member.setMobile(memberVo.getMobile());
        member.setAddress(memberVo.getAddress());
        member.setAge(memberVo.getAge());
        member.setEmail(memberVo.getEmail());
        shoppingSysMemberMapper.insert(member);
        return "添加成功";
    }

    @Override
    public String updateMember(MemberVo memberVo) {
        UpdateWrapper<ShoppingSysMember> wrapper = new UpdateWrapper<>();
        wrapper.eq("product_id",memberVo.getId());
        ShoppingSysMember member = new ShoppingSysMember();
        member.setLoginName(memberVo.getLoginName());
        member.setMemberName(memberVo.getMemberName());
        member.setPassword(memberVo.getPassword());
        member.setSex(memberVo.getSex());
        member.setMobile(memberVo.getMobile());
        member.setAddress(memberVo.getAddress());
        member.setAge(memberVo.getAge());
        member.setEmail(memberVo.getEmail());
        shoppingSysMemberMapper.update(member,wrapper);
        return "修改成功";
    }

    @Override
    public Page<ShoppingSysMember> selectMember(String name,int pageNo,int pageSize) {
        Page<ShoppingSysMember> page = new Page<>(pageNo,pageSize);
        QueryWrapper<ShoppingSysMember> wrapper = new QueryWrapper<>();
        wrapper.like("login_name",name);
        return shoppingSysMemberMapper.selectPage(page,wrapper);


    }
}
